function getGameData(data, game_id)
{
	var gameData = data[game_id]
	if (gameData)
		return gameData
	else
	{
		return {}
	}
}

function makeGameData(gameData)
{
	var title = $('#gameTitle').val()
	gameData["title"] = title
	
	info = {}
	info["name"] = title
	info["main"] = $('#gameDescription').val()
	info["results"] = "Good job!"
	
	gameData["info"] = info
	
	questions = []
	$(".designQuestion").each(function(index, obj) {
		question = {}
		question["q"] = $(obj).val()
		question["a"] = [ {"option" : "True", "correct" : true},
		                  {"option" : "False", "incorrect": false}
						  ]
		question["correct"] = "Correct!"
		question["incorrect"] = "That does not seem correct."
		questions.push(question)
	})
	
	gameData["questions"] = questions
}

function createGame()
{
	var title = $('#gameTitle').val()
	game_id = title.replace(" ", "_");
	
	var data = loadDataStorage()
	var gameData = getGameData(data, game_id)
	gameData["game_id"] = game_id
	makeGameData(gameData)
	data[game_id] = gameData
	saveDataStorage(data)
}

function saveGame()
{
	createGame()
}

$(document).on('click', '#designSave', function () {
  saveGame();
});

$(document).on('click', '#designSaveReturn', function () {
  saveGame();
});